import request from "@/request";

export const UserListAPI = (params: IUserListParams): RES<IUserListModel> =>
  request.get("/admin/list", { params });

export const SwitchUserStatusAPI = (
  id: number,
  status: number
): RES<IUserModel> =>
  request.post(`/admin/updateStatus/${id}?status=${status}`);

export const addUserAPI = (params: IUserModel): RES<IUserModel> =>
  request.post("/admin/register", params);

export const getUserIdAPI = (id: number): RES<IUserModel> =>
  request.get(`/admin/${id}`);

export const updateUserAPI = (params: IUserModel): RES<number> =>
  request.post(`/admin/update/${params.id}`, params);

export const getRoleListAPI = (): RES<IRoleModel[]> =>
  request.get("/role/listAll");

export const RoleListAPI = (
  params: IUserListParams
): RES<IRoleListModel<IRoleModel>> => request.get(`/role/list`, { params });

export const switchRoleStatusAPI = (id: number, status: number): RES<number> =>
  request.post(`/role/updateStatus/${id}?status=${status}`);

export const getRolesByUserIdAPI = (adminId: number): RES<IRoleModel[]> =>
  request.get(`admin/role/${adminId}`);

export const updateUserRolesAPI = (id: number, ids: number[]): RES<number> =>
  request.post(`/admin/role/update?adminId=${id}&roleIds=${ids.join(",")}`);

export const getResourceListByIdAPI = (roleId: number): RES<IResourceModel[]> =>
  request.get(`role/listResource/${roleId}`);

export const resourceListAllAPI = (): RES<IResourceModel[]> =>
  request.get("/resource/listAll");

export const resourceCategoryAllAPI = (): RES<IResourceCategoryModel[]> =>
  request.get("/resourceCategory/listAll");

export const editRoleAPI = (params: IRoleModel): RES<number> =>
  request.post(`/role/update/${params.id}`, params);

export const addRoleAPI = (params: IRoleModel): RES<IRoleModel> =>
  request.post("/role/create", params);

export const allocResourceAPI = (paramas: allocResourcePramas) =>
  request.post(
    `/role/allocResource?roleId=${
      paramas.roleId
    }&resourceIds=${paramas.resourceIds.join(",")}`
  );

export const treeListApi = (): RES<ItreeMenu[]> =>
  request.get("/menu/treeList");
